package cn.bone.base.bean;

/**
 * Created by superbone on 2017/4/21.
 * 返回值工具类
 */
public class Ref {

    /**请求成功,无返回值*/
    public static CommonResult<Void> ok(){
        CommonResult<Void> result = new CommonResult<>();
        result.setCode(0);
        result.setData(null);
        result.setMsg("成功");
        return result;
    }

    /**请求成功,有返回值T*/
    public static <T> CommonResult<T> ok(T o){
        CommonResult<T> result = new CommonResult<>();
        result.setCode(0);
        result.setData(o);
        result.setMsg("成功");
        return result;
    }

    /**请求成功,没有返回值,有成功提示*/
    public static CommonResult<Void> okMsg(String msg){
        CommonResult<Void> result = new CommonResult<>();
        result.setCode(0);
        result.setData(null);
        result.setMsg(msg);
        return result;
    }

    /**请求成功,有返回值T和成功提示*/
    public static <T> CommonResult<T> okMsg(T o, String msg){
        CommonResult<T> result = new CommonResult<>();
        result.setCode(0);
        result.setData(o);
        result.setMsg(msg);
        return result;
    }

    /**请求失败,业务逻辑错误*/
    public static <T> CommonResult<T> error(String errMsg){
        CommonResult<T> result = new CommonResult<>();
        result.setCode(3001);
        result.setData(null);
        result.setMsg(errMsg);
        return result;
    }

    /**服务器错误*/
    public static <T> CommonResult<T> serverError(String errMsg){
        CommonResult<T> result = new CommonResult<>();
        result.setCode(4001);
        result.setData(null);
        result.setMsg(errMsg);
        return result;
    }

    /**接口不存在*/
    public static <T> CommonResult<T> noExistApi(){
        CommonResult<T> result = new CommonResult<>();
        result.setCode(1003);
        result.setData(null);
        result.setMsg("接口不存在");
        return result;
    }

    /**接口不可用*/
    public static <T> CommonResult<T> disableApi(){
        CommonResult<T> result = new CommonResult<>();
        result.setCode(1004);
        result.setData(null);
        result.setMsg("接口不可用");
        return result;
    }

    /**接口不支持该设备*/
    public static <T> CommonResult<T> notAllowDevice(){
        CommonResult<T> result = new CommonResult<>();
        result.setCode(1005);
        result.setData(null);
        result.setMsg("接口不支持该设备");
        return result;
    }

    /**接口调用random重复*/
    public static <T> CommonResult<T> RandomExist(){
        CommonResult<T> result = new CommonResult<>();
        result.setCode(1006);
        result.setData(null);
        result.setMsg("接口random重复");
        return result;
    }

    /**请求参数校验错误*/
    public static <T> CommonResult<T> errorParam(String message) {
        CommonResult<T> result = new CommonResult<>();
        result.setCode(1002);
        result.setData(null);
        result.setMsg(message);
        return result;
    }
}
